package com.example.bai7;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {
	Bundle backupBundle;
	Integer[] imgid;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         backupBundle=savedInstanceState;
      //  TextView txtview= (TextView) findViewById(R.id.txtview);
        
        
        GridView grid= (GridView) findViewById(R.id.grid);
        imgid=new Integer[]{R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,R.drawable.img5,R.drawable.img6,R.drawable.img7,R.drawable.img8,R.drawable.img9};
        
       MyImageAdapter adapter= new MyImageAdapter(MainActivity.this,imgid); 
       grid.setAdapter(adapter);
     grid.setOnItemClickListener(new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			showDetail(arg2);
		}
	});
    
    }
    
    private void showDetail(int ind)
    {
    	setContentView(R.layout.solo_img);
    	TextView txttext1= (TextView) findViewById(R.id.txttext1);
    	
    	Button btnback=(Button) findViewById(R.id.btnback);
    	
    	txttext1.setText("position: "+ind);
    	ImageView imgview= (ImageView) findViewById(R.id.imgview);
    	imgview.setImageResource(imgid[ind]);
    	
    	btnback.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onCreate(backupBundle);
			}
		});
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
